<?php
/****
	策略模式
****/
header('Content-type:text/html;charset=utf-8');

Interface Math{
	//计算
	public function calculate($left,$right);
}

class MathAdd implements Math{
	public function calculate($left,$right){
		return $left + $right;
	}
}

class MathSub implements Math{
	public function calculate($left,$right){
		return $left - $right;
	}
}

class MathMul implements Math{
	public function calculate($left,$right){
		return $left * $right;
	}
}

class MathDiv implements Math{
	public function calculate($left,$right){
		return $left / $right;
	}
}

//封装一个计算器
class ComputerMath{
	protected $math = null;

	public function __construct($type){
		$class = 'Math'.$type;
		$this->math = new $class();
	}

	public function calculate($left,$right){
		return $this->math->calculate($left,$right);
	}
}

print_r($_POST);
$type = $_POST['operate'];
$math = new ComputerMath($type);
echo $math->calculate($_POST['left'],$_POST['right']);


